﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;

namespace Kkc.Application.Specifications
{
    public abstract class BinarySpecification<T>: Specification<T>
    {
        protected BinarySpecification(ISpecification<T> leftOperand, ISpecification<T> rightOperand)
        {
            if (leftOperand == null)
                throw new ArgumentNullException("leftOperand");

            if (rightOperand == null)
                throw new ArgumentNullException("rightOperand");

            expression = CreateBinaryExpression(leftOperand, rightOperand);
        }

        private readonly Expression<Func<T, bool>> expression;
        
        public override System.Linq.Expressions.Expression<Func<T, bool>> Expression
        {
            get { return expression; }
        }

        protected abstract Expression<Func<T, bool>> CreateBinaryExpression(ISpecification<T> leftOperand, ISpecification<T> rightOperand);
    }
}